package com.kingyea.mobilepolice.config.activemq;

import com.google.common.collect.Lists;
import com.kingyea.mobilepolice.systemsync.SystemSyncService;
import com.kingyea.mobilepolice.util.ApplicationContextUtil;
import com.kingyea.mobilepolice.util.GlobalVar;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 * 同步token用
 *
 * @author Mr.Lin
 * @version v1.0.0
 * @description
 * @date Created in 2018/4/24 19:30
 */
@Component
public class SyncTokenMessageListener_wai implements MessageListener {


    private SystemSyncService systemSyncService;


    @Override
    public void onMessage(Message message) {
        if (systemSyncService == null) {
            systemSyncService = ApplicationContextUtil.getBean(SystemSyncService.class);
        }
        System.out.println(systemSyncService);
        // 只有当前是外网的情况下，才主动把消息推到内网
        if (GlobalVar.inside.intValue() == GlobalVar.insideWai) {
            try {
                systemSyncService.sync(Lists.newArrayList(((TextMessage) message).getText()));
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }


}
